﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace SkiTracker.Converter
{
    /// <summary>
    /// Converts null to collapsed. Can be inverted either by setting the paramater to "inverse" or by setting the Inverse-property.
    /// </summary>
    public class NullToVisibilityConverter : IValueConverter
    {
        #region IValueConverter Members

        public NullToVisibilityConverter()
        {
            Inverse = false;
        }

        public bool Inverse { get; set; }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (targetType == typeof (Visibility))
            {
                bool inverse = parameter != null && parameter.ToString().ToLower() == "inverse";

                if (Inverse || inverse)
                {
                    return (value == null) ? Visibility.Visible : Visibility.Collapsed;
                }
                return (value == null) ? Visibility.Collapsed : Visibility.Visible;
            }
            return DependencyProperty.UnsetValue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}